Public Class TextBox
    Inherits WebControls.TextBox
    Implements IJObjective

    Private m_sNamespace As String
    Private m_sPropertyName As String
    Private m_sConstructor As String
    Private m_sDataID As String
    Private m_ctlSetFocus As New Variable

    Private m_iFormatter As Nullable(Of Formatter.Types)

    Public Property Formatter() As Nullable(Of Formatter.Types)
        Get
            Return m_iFormatter
        End Get
        Set(ByVal value As Nullable(Of Formatter.Types))
            m_iFormatter = value
        End Set
    End Property

    Public Property [Namespace]() As String Implements IJObjective.Namespace
        Get
            Return m_sNamespace
        End Get
        Set(ByVal value As String)
            m_sNamespace = value
        End Set
    End Property

    Public Property ObjectName() As String Implements IJObjective.ObjectName
        Get
            Return m_sPropertyName
        End Get
        Set(ByVal value As String)
            m_sPropertyName = value
        End Set
    End Property

    Public Property Constructor() As String Implements IJObjective.Constructor
        Get
            Return m_sConstructor
        End Get
        Set(ByVal value As String)
            m_sConstructor = value
        End Set
    End Property

    Public Property DataID() As String Implements IJObjective.DataID
        Get
            Return m_sDataID
        End Get
        Set(ByVal value As String)
            m_sDataID = value
        End Set
    End Property

    Public Property SetFocus() As Boolean
        Get
            Return CBool(m_ctlSetFocus.Value)
        End Get
        Set(ByVal value As Boolean)
            m_ctlSetFocus.Value = value.ToString.ToLower
        End Set
    End Property

    Public Overrides ReadOnly Property ClientID() As String
        Get
            Return ID
        End Get
    End Property

    Public Sub New()
        DataID = Common.GetUniqueID(Context)

        With m_ctlSetFocus
            .Name = "_setFocus"
        End With
    End Sub

    Protected Overrides Sub CreateChildControls()
        MyBase.CreateChildControls()

        ChildControlsCreated = True
    End Sub

    Private Sub TextBox_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        EnsureChildControls()

        If String.IsNullOrEmpty(Constructor) Then
            If Formatter.HasValue Then
                Constructor = "new jObjective.TextBox($('#" & DataID & "')," & Common.GetEnumDescription(Formatter.Value) & ")"
            Else
                Constructor = "new jObjective.TextBox($('#" & DataID & "'),null)"
            End If
        End If
    End Sub

    Private Sub TextBox_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ID = DataID

        If Not String.IsNullOrEmpty(m_ctlSetFocus.Value) Then
            With Controls
                .Add(m_ctlSetFocus)
            End With
        End If
    End Sub
End Class